import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_controller_lifecycle/4%E3%80%81Get.put%E5%92%8CGet.to%E5%90%8C%E4%B8%80%E4%B8%AA%E7%B1%BB%E4%B8%8D%E5%90%8C%E5%AE%9E%E4%BE%8B/put_same_class_detail_controller.dart';
import 'package:getx_controller_lifecycle/4%E3%80%81Get.put%E5%92%8CGet.to%E5%90%8C%E4%B8%80%E4%B8%AA%E7%B1%BB%E4%B8%8D%E5%90%8C%E5%AE%9E%E4%BE%8B/put_same_class_detail_page.dart';
import '../home_page.dart';

/// Get.put用tag区分controller,底层时通过routeName+tag作为key存储controller的
/// Get.to配置preventDuplicates: false 去除防止重复的限制，以达到跳转同Class（路由名称）的页面，
/// 场景例如：产品详情页1跳转产品详情页2

class PutSameClassPage extends StatelessWidget {
  const PutSameClassPage({Key? key}) : super(key: key);

  void toDetailPage1() {
    PutSameClassController model = PutSameClassController.randomInstance();
    Get.to(() => PutSameClassDetailPage(model: model,));
  }

  void toDetailPage2() {
    PutSameClassController model = PutSameClassController.randomInstance();
    Get.to(() => PutSameClassDetailPage(model: model,), preventDuplicates: false);
  }

  @override
  Widget build(BuildContext context) {
    PageAction action = Get.arguments;
    return Scaffold(
        appBar: AppBar(
          title: Text(
            action.name,
            style: const TextStyle(
                fontSize: 14
            ),
          ),
        ),
        backgroundColor: Colors.white,
        body: SingleChildScrollView(
          child: Column(
            children: [
              const Padding(
                padding: EdgeInsets.all(15),
                child: Text(
                  """
1、Get.put用tag区分controller,底层时通过routeName+tag作为key存储controller的
2、Get.to配置preventDuplicates: false 去除防止重复的限制，以达到跳转同Class（路由名称）的页面，
   场景例如：产品详情页1跳转产品详情页2
                  """,
                  maxLines: 100,
                  style: TextStyle(
                    fontSize: 15,
                  ),
                  strutStyle: StrutStyle(
                      leading: 0
                  ),
                ),
              ),
              Padding(
                padding: const EdgeInsets.symmetric(horizontal: 10),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    const Text("Get.to preventDuplicates=true无法跳转相同路由名的页面"),
                    ElevatedButton(onPressed: toDetailPage1, child: const Text("跳转1")),
                    const Text("Get.to preventDuplicates=false可以跳转相同路由名的页面"),
                    ElevatedButton(onPressed: toDetailPage2, child: const Text("跳转2")),
                  ],
                ),
              ),
            ],
          ),
        )
    );
  }
}
